'use strict';
var baseUrl = 'http://localhost:8080/rest/tea/';
var services = angular.module('sbAdminAppServices', ['ngResource'])
	.factory('TeacherService', ['$resource',
		function($resource) {
			return $resource(baseUrl + 'teachers/:action', {}, {
				authenticate: {
					method: 'POST',
					params: {
						'action': 'authenticate'
					},
					headers: {
						'Content-Type': 'application/x-www-form-urlencoded'
					}
				},
			});
		}
	]);
services.factory('CourseService', ['$resource',
	function($resource) {
		return $resource(baseUrl + 'courses/:couId', {
			couId: '@couId'
		}, {});
	}
]);

services.factory('StudentCourseService', ['$resource',
	function($resource) {
		return $resource(baseUrl + 'student_course/:action/:couId', {}, {
			getCourseStudents: {
				method: 'GET',
				params: {
					'action': 'getCourseStudents',
					'couId': '@couId'
				},
				isArray: true,
				headers: {
					'Content-Type': 'application/x-www-form-urlencoded'
				}
			}
		});
	}
]);

services.factory('LocateService', ['$resource',
	function($resource) {
		return $resource(baseUrl + 'locates/:action/:couId', {}, {
			getLocateByCouId: {
				method: 'GET',
				params: {
					'action': 'getLocateByCouId',
					'couId': '@couId'
				},
				isArray: true,
				headers: {
					'Content-Type': 'application/x-www-form-urlencoded'
				}
			},
			setLocateState: {
				method: 'POST',
				params: {
					'action': 'setLocateState',
					'couId': '@couId',
					'locState': '@locState'
				},
				headers: {
					'Content-Type': 'application/x-www-form-urlencoded'
				}
			}
		});
	}
]);

services.factory('NoticeInfoService', ['$resource',
	function($resource) {
		return $resource(baseUrl + 'notices/:notId:action/:couId', {
			couId: '@id'
		}, {
			getAll: {
				method: 'GET',
				params: {
					'action': 'getAll',
					'couId': '@id'
				},
				isArray: true,
				headers: {
					'Content-Type': 'application/x-www-form-urlencoded'
				}
			}
		});
	}
]);

services.factory('utils',
	function() {
		return {
			findCourseFromList: function(a, couId) {
				for (var i = 0; i < a.length; i++) {
					if (a[i].couId == couId) return a[i];
				}
				return null;
			}
		};
	});